﻿using System;
using System.IO.Ports;

namespace Communication.DataReceivedEvent.COM;

public class SerialPortEventInfo : IDataReceivedEventInfo
{
    private const int MaxLen = 1024 * 100;

    /// <summary>
    ///     使用的端口(例如COM1)。
    /// </summary>
    public required string PortName { get; init; }

    /// <summary>
    ///     波特率。
    /// </summary>
    public int BaudRate { get; init; }

    /// <summary>
    ///     指定 SerialPort 对象的奇偶校验位。
    /// </summary>
    public Parity Parity { get; init; }

    /// <summary>
    ///     数据位值。
    /// </summary>
    public int DataBits { get; init; }

    /// <summary>
    ///     指定SerialPort对象上使用的停止位数。
    /// </summary>
    public StopBits StopBits { get; init; }

    /// <summary>
    ///     读缓冲区大小
    /// </summary>
    public int ReadBufferSize { get; init; } = MaxLen;

    /// <summary>
    ///     写缓冲区大小
    /// </summary>
    public int WriteBufferSize { get; init; } = MaxLen;

    public DataReceivedEventDevice Type => DataReceivedEventDevice.Com;

    public string ToString(string? format, IFormatProvider? formatProvider)
    {
        return $"{Type}-{PortName}";
    }
}